<template>
  <h2>种母期初-新增</h2>
  <div>
    <el-form
      :model="form"
      label-width="auto"
      style="max-width: 1000px"
      :inline="true"
    >
      <el-button type="danger" @click="BeginAdd()">+ 新增</el-button>
      <el-button type="danger">保存</el-button>
      <el-button type="danger">撤销</el-button>
      <el-button type="danger">删除</el-button>
    </el-form>
  </div>
  <br />
  <table>
    <tr>
      <td>
        <el-form-item label="期初日期">
          <el-date-picker
            v-model="form.femalePeriodicPeriodicDate"
            type="date"
            placeholder="Pick a Date"
            format="YYYY-MM-DD"
            style="width: 150px"
          />
        </el-form-item>
      </td>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <td>
        <el-form-item label="单据号">
          <el-input v-model="form.femalePeriodicReceiptNumber"  style="width: 150px;"/>
        </el-form-item>
      </td>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <td>
        <el-form-item label="流水号">
          <el-input v-model="form.femalePeriodicSerialNumber" style="width: 150px;" />
        </el-form-item>
      </td>
    </tr>
  </table>
  <hr>
  <br>
  <table border="1" width="1000px">
    <tr>
      <td>序号</td>
      <td>耳号</td>
      <td>栋舍</td>
      <td>栏位</td>
      <td>转种日期</td>
      <td>重量</td>
    </tr>
    <div>
      
    </div>
    
  </table>
  <div v-if="form.Rang!=''">
     <tr>
      <td width="145px" style="text-align: center;background-color: #fff;color: #000;border-radius:5px">1</td>
      <td>
         <el-select v-model="form.breedingSheepArchiveId" placeholder="请选择" style="width: 145px;">
        <el-option v-for="item in EarData.filter(x=>x.sheepSex==2)" :label="item.auricle" :value="item.breedingSheepArchiveId" />
      </el-select>
      </td>
     <td>
      <el-select v-model="form.buildingId" placeholder="请选择" style="width: 145px;">
        <el-option v-for="item in BudData" :label="item.buildingName" :value="item.buildingId" 
        @click="GetColumns()"/>
      </el-select>
     </td>
      <td>
        <el-select v-model="form.columnsId" placeholder="请选择" style="width: 145px;">
        <el-option v-for="item in ColData" :label="item.columnsName" :value="item.columnsId" />
      </el-select>
      </td>
      <td>
          <el-date-picker
            v-model="form.transferDate"
            type="date"
            placeholder="Pick a Date"
            format="YYYY-MM-DD"
            style="width: 260px"
          />
      </td>
      <td>
        <el-input v-model="form.femalePeriodicWeight"  style="width: 150px;"/>
      </td>
    </tr>
  </div>
 
    <table style="margin-top: 200px;width: 1000px;" border="1" > 
      <tr>
        <td>合计</td>
      </tr>
      <tr>
        <td>
          <el-button type="danger" link @click="AddRang()">+增行</el-button>
          <el-button  type="danger" link @click="saveRang()">-减行</el-button>
        </td>
      </tr>
      <tr>
        <td>
          备注:<el-input v-model="form.remark" type="textarea"  />
        </td>
      </tr>
    </table>
</template>

<script setup lang="ts">
import axios from "axios";
import { ElMessage } from "element-plus";
import { reactive, onMounted, ref } from "vue";
onMounted(() => {
  GetEarNum();
});
const form = reactive({
  Rang:'',
  "femalePeriodicReceiptNumber": "",
  "femalePeriodicPeriodicDate": "",
  "femalePeriodicSerialNumber": "",
  "breedingSheepArchiveId": '',
  "buildingId": '',
  "columnsId": '',
  "transferDate": "",
  "femalePeriodicWeight": '',
  remark:""
});
//获取耳号
const EarData = ref([]);
function GetEarNum() {
  axios
    .post("http://localhost:5012/api/SheepFile/BasicInformationList", {})
    .then((res) => {
      console.log(res.data);
      EarData.value = res.data.data;
    });
}
const tableData = ref([])
//新增行
function AddRang()
{
 form.Rang='a';
 GetBudding()
}
function saveRang()
{
 form.Rang='';
}
//栋舍Id
const BudData=ref([])
function GetBudding()
{
  axios.post("http://localhost:5012/api/Buildings/BuildingList",{
    buildingTypeId:0,
    buildingName:"",
    buildingPerson:"",
    pageIndex:1,
    pageSize:50
  })
  .then(res=>{
    console.log(res);
    BudData.value=res.data.data.data
   
  })
}
//栏位显示
const ColData=ref([])
function GetColumns()
{
  axios.post("http://localhost:5012/api/Buildings/ColumnsList",{
    buildingId:form.buildingId
  })
  .then(res=>{
    console.log(res);
    ColData.value=res.data.data
  })
}
//种母期初新增
function BeginAdd()
{
  axios.post("http://localhost:5012/api/SheepFile/FemalePeriodicAdd",{
    femalePeriodicReceiptNumber:form.femalePeriodicReceiptNumber,
    femalePeriodicPeriodicDate:form.femalePeriodicPeriodicDate,
    femalePeriodicSerialNumber:form.femalePeriodicSerialNumber,
    breedingSheepArchiveId:form.breedingSheepArchiveId,
    buildingId:form.buildingId,
  columnsId:form.columnsId,
  transferDate:form.transferDate,
  femalePeriodicWeight:form.femalePeriodicWeight,
  remark:form.remark
  })
  .then(res=>{
    if(res.data.code==0)
    {
      ElMessage.success("新增成功");
    }
    else
    {
      ElMessage.error("新增成功");
    }
  })
}
</script>

<style scoped></style>
